<template>
<div style="padding:30px;">
    <el-alert
        title="订单查询"
        type="info"
        :closable="false"
        show-icon
        description="在此查看历史订单记录"
        effect="dark"/>

    <div>
        <div style="padding:20px">
        <el-select v-model="passenger_card" clearable placeholder="请选择乘车人" v-has="'add'">
        <el-option
        v-for="item in passengerList"
        :key="item.value"
        :label="item.label"
        :value="item.value">
        </el-option>
        </el-select>
        <el-select v-model="orderType" clearable placeholder="请选择订单类型">
        <el-option
        v-for="item in orderTypeList"
        :key="item.value"
        :label="item.label"
        :value="item.value">
        </el-option>
        </el-select>
        <el-button icon="el-icon-search" type="primary" @click="queryOrderBy"></el-button>
        </div>
        <el-table
         :data="orderList"
         border
         fit
         v-loading="tableLoading"
         >
            <el-table-column width="80" label="乘车人">
                <template slot-scope="scope">
                    {{ scope.row.passenger_name }}
                </template>
            </el-table-column>
            <el-table-column width="80" label="身份证号">
                <template slot-scope="scope">
                    {{ scope.row.passenger_card }}
                </template>
            </el-table-column>
            <el-table-column width="130" label="座位信息">
                <template slot-scope="scope">
                {{ scope.row.carriage_no}}车厢--{{ seatDetail(scope.row.carriage_no,scope.row.seat_no) }}
                </template>
            </el-table-column>
            <el-table-column width="130" label="发车日期">
                <template slot-scope="scope">
                    <i class="el-icon-time"></i>
                   <span style="margin-left:10px"> {{scope.row.arrive_day}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="start_station_name" width="80" label="起始站"></el-table-column>
            <el-table-column width="80" label="发车时间">
                <template slot-scope="scope">
                    {{scope.row.start_time}}
                </template>
            </el-table-column>
            <el-table-column prop="end_station_name" width="80" label="终点站"></el-table-column>
            <el-table-column width="80" label="到站时间">
                <template slot-scope="scope">
                    {{scope.row.end_time}}
                </template>
            </el-table-column>
            <el-table-column width="80" label="到达日期">
                <template slot-scope="scope">
                    {{judgeArrive(scope.row)}}
                </template>
            </el-table-column>
            <el-table-column prop="price" width="80" label="支付金额"></el-table-column>
            <el-table-column prop="status" width="80px" label="订单类型"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="{row,$index}">
                    <el-button type="success" size="small" v-if="row.status==='未支付'" @click="handlePay(row)">支付</el-button>
                    <el-button type="primary" size="small" v-if="row.status==='已付款'&&canRebook(row)" @click="handleRebook(row,$index)">改签</el-button>
                    <el-button type="danger"  size="small" v-if="canRefund(row) && row.status==='已付款'" @click="handleRefund(row,$index)" v-loading="refundLoading">退票</el-button>
                    <el-button type="warning" size="small" v-if="row.status==='已超时'||row.status==='已退票'||row.status==='已改签'" @click="handleDelete(row,$index)" v-has="'add'">删除</el-button>
                    <el-button style="background-color: red; color: white;" size="small" v-has="'add'" v-if="row.status==='已付款'" @click="handleClose(row,$index)">关停</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-dialog title="改签" :visible.sync="dialogFormVisible" width="80%">
        <div style="padding:10px">
        <el-steps :active="active" finish-status="success" simple>
        <el-step title="选择改签日期"></el-step>
        <el-step title="选择车次及座位"></el-step>
        <el-step title="多退少补"></el-step>
        </el-steps>
        </div>
        <el-dialog title="选座" :visible.sync="dialogSeatVisible" width="50%" append-to-body>
            <div>
                <el-table :data="seat_info"  style="width: 100%" border>
                    <el-table-column width="70" prop="carriage_no" label="车厢号"></el-table-column>
                    <el-table-column width="70" prop="seat_type" label="类型"></el-table-column>
                    <el-table-column width="50" prop="A" label="A"></el-table-column>
                    <el-table-column width="50" prop="B" label="B"></el-table-column>
                    <el-table-column width="50" prop="C" label="C"></el-table-column>
                    <el-table-column width="50" prop="D" label="D"></el-table-column>
                    <el-table-column width="50" prop="E" label="E"></el-table-column>
                    
                        <el-table-column label="选择">
                            <template slot-scope="scope">
                                <el-button-group>
                                <el-button  type="primary" size="small" @click="selectA(scope.row)" :disabled="scope.row.A===0">A</el-button>
                                <el-button type="primary" size="small" @click="selectB(scope.row)" :disabled="scope.row.B===0">B</el-button>
                                <el-button :disabled="scope.row.C===0" @click="selectC(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '3' || scope.row.carriage_no === '4' || scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7' || scope.row.carriage_no === '8'">C</el-button>
                                <el-button :disabled="scope.row.D===0" @click="selectD(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7'|| scope.row.carriage_no === '8'">D</el-button>
                                <el-button :disabled="scope.row.E===0" @click="selectE(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7'|| scope.row.carriage_no === '8'">E</el-button>
                        </el-button-group>
                            </template>
                    </el-table-column>
                </el-table>
            </div>
        </el-dialog>
        <div v-if="active>=0">
            <el-card class="box-card" style="text-align: center;">
                <el-date-picker
                v-model="listQuery.new_arrive_day"
                value-format="yyyy-MM-dd"
                align="right"
                type="date"
                placeholder="选择日期"
                :picker-options="pickerOptions">
                </el-date-picker>
                <el-button type="primary" @click="handleQueryTrain">搜索</el-button>
                <el-table
                :data="trainList"
                v-loading="trainListLoading"
                border
                fit>
                <el-table-column label="车次"  align="center">
                <template slot-scope="scope">
                    {{ scope.row.train_number }}
                </template>
                </el-table-column>
                <el-table-column label="起始站"  align="center">
                <template slot-scope="scope">
                    <span >{{ scope.row.start_station }}</span>
                </template>
                </el-table-column>
                <el-table-column label="终点站"  align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.end_station }}</span>
                </template>
                </el-table-column>
                <el-table-column align="center"  label="发车时间" >
                <template slot-scope="scope">
                    <i class="el-icon-time" />
                    <span>{{ scope.row.start_time }}</span>
                </template>
                </el-table-column>
        
                <el-table-column align="center" label="到站时间">
                <template slot-scope="scope">
                    <i class="el-icon-time" />
                    <span>{{ scope.row.end_time }}</span>
                </template>
                </el-table-column>
        
                <el-table-column align="center" label="发车日期">
                <template slot-scope="scope">
                    <i class="el-icon-time" />
                    <span>{{ scope.row.arrive_day }}</span>
                </template>
                </el-table-column>
                <el-table-column label="操作" align="center"  class-name="small-padding fixed-width">
                <template slot-scope="{row,$index}">
                    <el-button size="mini" type="danger" @click="selectSeat(row)">
                    选座
                    </el-button>
                </template>
                </el-table-column>
                </el-table>
            </el-card>
        </div>
        </el-dialog>
        <el-dialog title="异常处理，强制退单" :visible.sync="dialogOrderVisible">
            <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="reason">
            </el-input>
            <el-button type="success" @click="handleSend">发送</el-button>
        </el-dialog>
    </div>
</div>
</template>

<script>
import {getList,getKind} from '@/api/table'
import {payTicket,queryOrder,deleteOrder,refundTicket,rebook1,rebook2,rebookpay,rebook,queryAllOrder} from '@/api/order'
import {queryTrain,querySeat} from '@/api/train'
import {sendMsg,getEmail} from '@/api/user'
import { mapGetters } from 'vuex'
import moment from "moment"
import hasDirective from "@/directives/has";

 export default{
    name:'Order',
    directives: {
    has: hasDirective,
  },
    data(){
        return{
            currentEmail:'',
            dialogOrderVisible:false,
            refundLoading:false,
            reason:'',
            currentRow:undefined,
            currentIndex:undefined,
            passengerList:[],
            passenger_card:'',
            orderType:'',
            orderList:[],
            orderTypeList:[
                {
                    value: '未支付',
                    label: '未支付'
                },
                {
                    value: '已付款',
                    label: '已付款'
                },
                {
                    value: '已超时',
                    label: '已超时'
                },
                {
                    value: '已退票',
                    label: '已退票'
                },
                {
                    value: '已改签',
                    label: '已改签'
                }
            ],
            tableLoading:true,
            dialogFormVisible:false,
            active:0,
            listQuery:{
                new_arrive_day:'',
                end_station:'',
                start_station:'',
            },
            new_arrive_day:null,
            trainList:[],
            trainListLoading:false,
            dialogSeatVisible:false,
            seat_info:[],
            oldOrder:null,
            newOrder:null,
            occupation:null,
            orignPrice:0,
            baseCost:0,
            realCost:0,
            nowTrain:null,
            create_time:null,
            seat_no:null,
            passengerKind:null,
            charge:null,
            pickerOptions: {
            disabledDate(time) {
              return time.getTime() < new Date().getTime() - 24 * 60 * 60 * 1000;
            },
            shortcuts: [{
              text: '今天',
              onClick(picker) {
                picker.$emit('pick', new Date());
              }
            }]
          },
        }
    },
    computed: {
        ...mapGetters([
        'name',
        'email'
        ])
    },
    created(){
        console.log(this.email,'&&&&^^^&&&')
        getList({username: this.name}).then(response => {
        var allPassenger = response.data.data
        allPassenger.forEach(element =>{
            this.passengerList.push({value:element.card,label:element.name})
        })
        })
        console.log(this.name)
        if(this.name=='admin'){
            queryAllOrder().then(response =>{
                this.orderList=response.data.data
                this.tableLoading=false
            })
        }
        else{
            queryOrder({username:this.name,passenger_card:this.passenger_card,order_status:this.orderType}).then(response =>{
            this.orderList=response.data.data
            this.tableLoading=false
        })
        }
       
    },
    methods: {
        handleClose(row,index){
            this.dialogOrderVisible=true
            console.log(row)
            getEmail({user_id:row.user_id}).then(response =>{
                this.currentEmail=response.data.email
                this.currentRow=row
                this.currentIndex=index
            })
        },
        handleSend(){
            sendMsg({email:this.currentEmail,text:this.reason}).then(response =>{
                this.$notify({
                title: '成功',
                message: '为用户发'+this.currentEmail+'送消息成功！',
                type: 'success'
                });
                this.handleForce(this.currentRow,this.currentIndex)
                this.dialogOrderVisible=false
            })
        },
        judgeArrive(row){
            if(moment('2018-10-20 '+row.start_time).isBefore('2018-10-20 '+row.end_time)){
                return '当日到达'
            }
            else{
                return '次日到达'
            }
        },
        seatDetail(c_no,s_no){
        if(c_no==='1'||c_no==='2'){
            if(s_no%2===0){
                return (s_no/2)+"排B座"
            }
            else{
                return (parseFloat(s_no/2).toFixed(0))+"排A座"
            }
        }
        if(c_no ==='3' || c_no==='4'){
            if(s_no%3===0){
                return (s_no/3)+"排C座"
            }
            else if(s_no%3===2){
                return (parseInt(s_no/3)+1)+"排B座"
            }
            else{
                return (parseInt(s_no/3)+1)+"排A座"
            }
        }
        if(c_no === '5' || c_no === '6' || c_no === '7' || c_no === '8'){
            if(s_no%5===0){
                return (s_no/5)+"排E座"
            }
            else if(s_no%5===4){
                return (parseInt(s_no/5)+1)+"排D座"
            }
            else if(s_no%5===3){
                return (parseInt(s_no/5)+1)+"排C座"
            }
            else if(s_no%5===2){
                return (parseInt(s_no/5)+1)+"排B座"
            }
            else if(s_no%5===1){
                return (parseInt(s_no/5)+1)+"排A座"
            }
        }
        },
        queryOrderBy(){
            this.tableLoading=true
            queryOrder({username:this.name,passenger_card:this.passenger_card,order_status:this.orderType})
            .then(response =>{
                this.orderList=response.data.data
                this.tableLoading=false
                this.$notify({
                title: '成功',
                message: '查询成功',
                type: 'success'
                });
            })
        },
        handleDelete(row,index){
        this.$confirm('此操作将永久删除该订单记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.orderList.splice(index,1)
            deleteOrder({order_id:row.id})
            this.$message({
                type: 'success',
                message: '删除成功!'
            });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
        },
        canRefund(row){
            // var nowTime = moment().format("YYYY-MM-DD HH:mm")
            // var compareTime = row.arrive_day+' '+row.start_time
            // var last = moment(compareTime).diff(moment(nowTime),'minutes')
            // if(last>360)
            // {
            //     return true
            // }
            // else{
            //     return false
            // }
            return true
        },
        handleForce(row,index){
            this.charge=0
            refundTicket({order_id:row.id,train_no:row.train_no,passenger_card:row.passenger_card,arrive_day:row.arrive_day,user_id:row.user_id,price:row.price,carriage_no:row.carriage_no,cha:this.charge})
            .then(response =>{
                this.$message({
                type: 'success',
                message: '退票成功!'
                });
                this.orderList[index].status='已退票'
            })
        },
        handleRefund(row,index){
            
            var nowTime = moment().format("YYYY-MM-DD HH:mm")
            var compareTime = row.arrive_day+' '+row.start_time
            var last = moment(compareTime).diff(moment(nowTime),'minutes')
            var text=''
            if(last>=2880){
                text='离发车时间超过48小时,手续费为票价的5%！'
                this.charge=parseFloat(parseInt(row.price.substr(1,row.price.length))*0.05).toFixed(0)
            }
            else if(last<2880 && last>=1440){
                text='离发车时间超过24小时且不足48小时,手续费为票价的10%！'
                this.charge=parseFloat(parseInt(row.price.substr(1,row.price.length))*0.1).toFixed(0)
            }
            else{
                text='离发车时间不足24小时,手续费为票价的20%！'
                this.charge=parseFloat(parseInt(row.price.substr(1,row.price.length))*0.2).toFixed(0)
            }
        this.$confirm(text+'手续费为:'+this.charge+'元', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.refundLoading=true
            refundTicket({order_id:row.id,train_no:row.train_no,passenger_card:row.passenger_card,arrive_day:row.arrive_day,user_id:row.user_id,price:row.price,carriage_no:row.carriage_no,cha:this.charge})
            .then(response =>{
                this.refundLoading=false
                this.$message({
                type: 'success',
                message: '退票成功!'
                });
                this.orderList[index].status='已退票'
            }).catch(response =>{
                this.refundLoading=false
            })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退票'
          });          
        });
        },
        canRebook(row){
            return true
            // var nowTime = moment().format("YYYY-MM-DD HH:mm")
            // var compareTime = row.arrive_day+' '+row.start_time
            // var last = moment(compareTime).diff(moment(nowTime),'minutes')
            // if(last>120)
            // {
            //     return true
            // }
            // else{
            //     return false
            // }
        },
        handleRebook(row,index){
            console.log(row)
            this.dialogFormVisible=true
            this.listQuery.start_station=row.start_station_name
            this.listQuery.end_station=row.end_station_name
            this.trainList=[]
            this.orignPrice=parseInt(row.price.substr(1,row.price.length))
            this.oldOrder=row
            getKind({passenger_card:row.passenger_card}).then(response =>{
                this.passengerKind=response.data.kind
            })
            
        },
        handleQueryTrain(){
            
            if(this.listQuery.new_arrive_day===''){
                this.$notify({
                title: '警告',
                message: '改签日期不能为空！',
                type: 'warning'
            });
            }
            else{
                this.trainListLoading=true
                queryTrain({arrive_day:this.listQuery.new_arrive_day,start_station:this.listQuery.start_station,end_station:this.listQuery.end_station})
                .then(response =>{
                    this.trainList=response.data.data
                    this.trainListLoading=false
                    this.active=1
                    this.$notify({
                    title: '成功',
                    message: '查找成功',
                    type: 'success',
                    duration: 2000
                    })
                })
            }
        },
        selectSeat(row){
            this.dialogSeatVisible=true
            this.nowTrain=row
            this.active=2
            console.log(row)
            querySeat({train_no:row.train_no,arrive_day:row.arrive_day,start_station_no:row.start_station_no,end_station_no:row.end_station_no})
            .then(response =>{
            this.seat_info=response.data.data
            this.occupation=response.data.cook
            this.seat_info.forEach(ite =>{
                if(ite.carriage_no === '1' || ite.carriage_no === '2'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",'----')
                    this.$set(ite,"D",'----')
                    this.$set(ite,"E","----")
                }
                if(ite.carriage_no === '3' || ite.carriage_no ==='4'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",10)
                    this.$set(ite,"D",'----')
                    this.$set(ite,"E","----")
                }
                if(ite.carriage_no === '5' || ite.carriage_no === '6' || ite.carriage_no === '7' || ite.carriage_no === '8'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",10)
                    this.$set(ite,"D",10)
                    this.$set(ite,"E",10)
                }
            })
            this.seat_info.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                        }
                        if(element.carriage_no === '3'||element.carriage_no === '4'){
                            if(item.seat_no%3===0){occuC++}
                            else if(item.seat_no%3===2){occuB++}
                            else{occuA++}
                        }
                        if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                            if(item.seat_no%5===0){occuE++}
                            else if(item.seat_no%5===4){occuD++}
                            else if(item.seat_no%5===3){occuC++}
                            else if(item.seat_no%5===2){occuB++}
                            else{occuA++}
                        }
                    }
                })
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                        }
                        if(element.carriage_no === '3'||element.carriage_no === '4'){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                            element.C=element.C-occuC
                        
                        }
                        if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                            element.C=element.C-occuC
                            element.D=element.D-occuD
                            element.E=element.E-occuE
                        }
            })
            if(moment('2018-10-20 '+row.start_time).isBefore('2018-10-20 '+row.end_time)){
            this.baseCost = moment('2021-08-17 '+row.end_time).diff(moment('2021-08-17 '+row.start_time),'minutes')*0.833
            }
            else{
            this.baseCost = moment('2021-08-18 '+row.end_time).diff(moment('2021-08-17 '+row.start_time),'minutes')*0.833
            }
            })
        },
        selectA(row){
            //nowTrain是本车次的信息，row是本车厢的信息
            //得到新座位的费用，以便计算差价
            if(this.passengerKind==='儿童'||this.passengerKind ==='老人'){
                this.realCost=this.baseCost*0.5
            }
            else if(this.passengerKind === '学生'){this.realCost=this.baseCost*0.75}
            else{this.realCost=this.baseCost}
            //对车厢号进行判断后，以便得到座号，以及创建时间
        if(row.carriage_no === '1' || row.carriage_no === '2'){
            this.realCost=parseFloat(this.realCost*3).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
            this.occupation=response.data.cook
            var empty_A=['1','3','5','7','9','11','13','15','17','19']
            this.occupation.forEach(element =>{
                if(element.carriage_no === row.carriage_no && element.seat_no%2 ===1){
                    empty_A.forEach((item,index)=>{
                    if(item === element.seat_no){
                        empty_A.splice(index,1)
                    }
                    })
                }
            })
            this.seat_no=empty_A[0]
            console.log("座号",this.seat_no)
            this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
            }
        else if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost=parseFloat(this.realCost*1.5).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
                this.occupation=response.data.cook
                var empty_A=['1','4','7','10','13','16','19','22','25','28']
                this.occupation.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===1){
                        empty_A.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_A.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no=empty_A[0]
                console.log("座号",this.seat_no)
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost=parseFloat(this.realCost*1.0).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
                this.occupation=response.data.cook
                var empty_A=['1','6','11','16','21','26','31','36','41','46']
                this.occupation.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===1){
                        empty_A.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_A.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no=empty_A[0]
                console.log("座号",this.seat_no)
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        //int化，以便进行差价判断
        this.realCost=parseInt(this.realCost)
        //具体的差价判断逻辑
        //1.需要补钱
        if(this.orignPrice<this.realCost){
            console.log('需要补差价'+(this.realCost-this.orignPrice)+"元")
          this.$confirm("需要补差价"+(this.realCost-this.orignPrice)+"元"+",选购此座位？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            rebook2({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
            .then(response =>{
                console.log("haha")
                this.newOrder=response.data.data
                this.newOrder['charge']=this.realCost-this.orignPrice
            
            //此处更新表中座位信息
            if(response.code===200){
                //直接进行购票
                rebookpay(this.newOrder).then(response =>{
                    var url=response.data.url
                    loading.close()
                    window.open(url, "_blank")
                    
                })
                //更新数据
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                this.occupation=response.data.cook
                this.seat_info.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
                })
                var temp =this.oldOrder
                temp['order_id']=this.oldOrder.id
                rebook(temp).then(response =>{
                    this.active=3
                    this.$message({
                    message:response.data.message,
                    type:'success'
            })
                })
                
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
        }
        //2.不需补钱
        else if(this.orignPrice==this.realCost){
            this.$confirm("不需要补差价，选购此座位？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            //进入直接创建新的订单，并自动支付
            rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
            .then(response =>{
            if(response.code===200){
                //更新数据
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                this.occupation=response.data.cook
                this.seat_info.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
                })
                var temp =this.oldOrder
                temp['order_id']=this.oldOrder.id
                //直接将旧订单修改为已改签
                rebook(temp).then(response =>{
                    loading.close()
                    this.active=3
                    console.log("wawaaw")
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                })
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
        }
        else{
            console.log('退还'+(this.orignPrice-this.realCost)+"元")
            this.$confirm("退还"+(this.orignPrice-this.realCost)+"元"+"，选购此座位？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            //进入直接创建新的订单，并自动支付
            rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
            .then(response =>{
            if(response.code===200){
                //更新数据
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                this.occupation=response.data.cook
                this.seat_info.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
                })
                var temp =this.oldOrder
                temp['order_id']=this.oldOrder.id
                //直接将旧订单修改为已改签
                rebook(temp).then(response =>{
                    loading.close()
                    this.active=3
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                })
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
        }
        },
        selectB(row){
            //nowTrain是本车次的信息，row是本车厢的信息
            //得到新座位的费用，以便计算差价
            if(this.passengerKind==='儿童'||this.passengerKind ==='老人'){
                this.realCost=this.baseCost*0.5
            }
            else if(this.passengerKind === '学生'){this.realCost=this.baseCost*0.75}
            else{this.realCost=this.baseCost}
            //对车厢号进行判断后，以便得到座号，以及创建时间
        if(row.carriage_no === '1' || row.carriage_no === '2'){
            this.realCost=parseFloat(this.realCost*3).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
                this.occupation=response.data.cook
                var empty_B=['2','4','6','8','10','12','14','16','18','20']
                this.occupation.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%2===0){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no=empty_B[0]
                console.log("座号",this.seat_no)
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost=parseFloat(this.realCost*1.5).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
                this.occupation=response.data.cook
                var empty_B=['2','5','8','11','14','17','20','23','26','29']
                this.occupation.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===2){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no=empty_B[0]
                console.log("座号",this.seat_no)
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost=parseFloat(this.realCost*1.0).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
                this.occupation=response.data.cook
                var empty_B=['2','7','12','17','22','27','32','37','42','47']
                this.occupation.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===2){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no=empty_B[0]
                console.log("座号",this.seat_no)
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        this.realCost=parseInt(this.realCost)
        if(this.orignPrice<this.realCost){
            console.log('需要补差价'+(this.realCost-this.orignPrice)+"元")
          this.$confirm("需要补差价"+(this.realCost-this.orignPrice)+"元"+",选购此座位？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            rebook2({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
            .then(response =>{
                console.log("haha")
                this.newOrder=response.data.data
                this.newOrder['charge']=this.realCost-this.orignPrice
            
            //此处更新表中座位信息
            if(response.code===200){
                //直接进行购票
                rebookpay(this.newOrder).then(response =>{
                    var url=response.data.url
                    loading.close()
                    window.open(url, "_blank")
                    
                })
                //更新数据
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                this.occupation=response.data.cook
                this.seat_info.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
                })
                var temp =this.oldOrder
                temp['order_id']=this.oldOrder.id
                rebook(temp).then(response =>{
                    this.active=3
                    this.$message({
                    message:response.data.message,
                    type:'success'
            })
                })
                
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
        }
        //2.不需补钱
        else if(this.orignPrice==this.realCost){
            this.$confirm("不需要补差价，选购此座位？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            //进入直接创建新的订单，并自动支付
            rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
            .then(response =>{
            if(response.code===200){
                //更新数据
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                this.occupation=response.data.cook
                this.seat_info.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
                })
                var temp =this.oldOrder
                temp['order_id']=this.oldOrder.id
                //直接将旧订单修改为已改签
                rebook(temp).then(response =>{
                    loading.close()
                    this.active=3
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                })
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
        }
        else{
            console.log('退还'+(this.orignPrice-this.realCost)+"元")
            this.$confirm("退还"+(this.orignPrice-this.realCost)+"元"+"，选购此座位？", '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            //进入直接创建新的订单，并自动支付
            rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
            .then(response =>{
            if(response.code===200){
                //更新数据
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                this.occupation=response.data.cook
                this.seat_info.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
                })
                var temp =this.oldOrder
                temp['order_id']=this.oldOrder.id
                //直接将旧订单修改为已改签
                rebook(temp).then(response =>{
                    loading.close()
                    this.active=3
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                })
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
        }
        this.active=3
        },
        selectC(row){
            //nowTrain是本车次的信息，row是本车厢的信息
                //得到新座位的费用，以便计算差价
                if(this.passengerKind==='儿童'||this.passengerKind ==='老人'){
                    this.realCost=this.baseCost*0.5
                }
                else if(this.passengerKind === '学生'){this.realCost=this.baseCost*0.75}
                else{this.realCost=this.baseCost}
            if(row.carriage_no === '3' || row.carriage_no === '4'){
                this.realCost=parseFloat(this.realCost*1.5).toFixed(0)
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                    this.occupation=response.data.cook
                    var empty_C=['3','6','9','12','15','18','21','24','27','30']
                    this.occupation.forEach(element =>{
                        if(element.carriage_no === row.carriage_no && element.seat_no%3===0){
                            empty_C.forEach((item,index) =>{
                                if(item === element.seat_no){
                                    empty_C.splice(index,1)
                                }
                            })
                        }
                    })
                    this.seat_no=empty_C[0]
                    console.log("座号",this.seat_no)
                    this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
                })
            }
            else{
                this.realCost=parseFloat(this.realCost*1.0).toFixed(0)
                querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                .then(response =>{
                    this.occupation=response.data.cook
                    var empty_C=['3','8','13','18','23','28','33','38','43','48']
                    this.occupation.forEach(element =>{
                        if(element.carriage_no === row.carriage_no && element.seat_no%5===3){
                            empty_C.forEach((item,index) =>{
                                if(item === element.seat_no){
                                    empty_C.splice(index,1)
                                }
                            })
                        }
                    })
                    this.seat_no=empty_C[0]
                    console.log("座号",this.seat_no)
                    this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
                })
            }
            this.realCost=parseInt(this.realCost)
            if(this.orignPrice<this.realCost){
                console.log('需要补差价'+(this.realCost-this.orignPrice)+"元")
            this.$confirm("需要补差价"+(this.realCost-this.orignPrice)+"元"+",选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                rebook2({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                    console.log("haha")
                    this.newOrder=response.data.data
                    this.newOrder['charge']=this.realCost-this.orignPrice
                
                //此处更新表中座位信息
                if(response.code===200){
                    //直接进行购票
                    rebookpay(this.newOrder).then(response =>{
                        var url=response.data.url
                        loading.close()
                        window.open(url, "_blank")
                        
                    })
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    rebook(temp).then(response =>{
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                })
                    })
                    
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
            //2.不需补钱
            else if(this.orignPrice==this.realCost){
                this.$confirm("不需要补差价，选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                //进入直接创建新的订单，并自动支付
                rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                if(response.code===200){
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    //直接将旧订单修改为已改签
                    rebook(temp).then(response =>{
                        loading.close()
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                    })
                    })
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
            else{
                console.log('退还'+(this.orignPrice-this.realCost)+"元")
                this.$confirm("退还"+(this.orignPrice-this.realCost)+"元"+"，选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                //进入直接创建新的订单，并自动支付
                rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                if(response.code===200){
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    //直接将旧订单修改为已改签
                    rebook(temp).then(response =>{
                        loading.close()
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                    })
                    })
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
        },    
        selectD(row){
            if(this.passengerKind==='儿童'||this.passengerKind ==='老人'){
                    this.realCost=this.baseCost*0.5
                }
                else if(this.passengerKind === '学生'){this.realCost=this.baseCost*0.75}
                else{this.realCost=this.baseCost}
            this.realCost=parseFloat(this.realCost*1.0).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
                this.occupation=response.data.cook
                var empty_D=['4','9','14','19','24','29','34','39','44','49']
                this.occupation.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===4){
                        empty_D.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_D.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no=empty_D[0]
                console.log("座号",this.seat_no)
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
            this.realCost=parseInt(this.realCost)
            if(this.orignPrice<this.realCost){
                console.log('需要补差价'+(this.realCost-this.orignPrice)+"元")
            this.$confirm("需要补差价"+(this.realCost-this.orignPrice)+"元"+",选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                rebook2({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                    console.log("haha")
                    this.newOrder=response.data.data
                    this.newOrder['charge']=this.realCost-this.orignPrice
                
                //此处更新表中座位信息
                if(response.code===200){
                    //直接进行购票
                    rebookpay(this.newOrder).then(response =>{
                        var url=response.data.url
                        loading.close()
                        window.open(url, "_blank")
                        
                    })
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    rebook(temp).then(response =>{
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                })
                    })
                    
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
            //2.不需补钱
            else if(this.orignPrice==this.realCost){
                this.$confirm("不需要补差价，选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                //进入直接创建新的订单，并自动支付
                rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                if(response.code===200){
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    //直接将旧订单修改为已改签
                    rebook(temp).then(response =>{
                        loading.close()
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                    })
                    })
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
            else{
                console.log('退还'+(this.orignPrice-this.realCost)+"元")
                this.$confirm("退还"+(this.orignPrice-this.realCost)+"元"+"，选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                //进入直接创建新的订单，并自动支付
                rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                if(response.code===200){
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    //直接将旧订单修改为已改签
                    rebook(temp).then(response =>{
                        loading.close()
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                    })
                    })
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
        },
        selectE(row){
            //nowTrain是本车次的信息，row是本车厢的信息
                //得到新座位的费用，以便计算差价
                if(this.passengerKind==='儿童'||this.passengerKind ==='老人'){
                    this.realCost=this.baseCost*0.5
                }
                else if(this.passengerKind === '学生'){this.realCost=this.baseCost*0.75}
                else{this.realCost=this.baseCost}
            this.realCost=parseFloat(this.realCost*1.0).toFixed(0)
            querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
            .then(response =>{
                this.occupation=response.data.cook
                var empty_E=['5','10','15','20','25','30','35','40','45','50']
                this.occupation.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===0){
                        empty_E.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_E.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no=empty_E[0]
                console.log("座号",this.seat_no)
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
            this.realCost=parseInt(this.realCost)
            if(this.orignPrice<this.realCost){
                console.log('需要补差价'+(this.realCost-this.orignPrice)+"元")
            this.$confirm("需要补差价"+(this.realCost-this.orignPrice)+"元"+",选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                rebook2({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                    console.log("haha")
                    this.newOrder=response.data.data
                    this.newOrder['charge']=this.realCost-this.orignPrice
                
                //此处更新表中座位信息
                if(response.code===200){
                    //直接进行购票
                    rebookpay(this.newOrder).then(response =>{
                        var url=response.data.url
                        loading.close()
                        window.open(url, "_blank")
                        
                    })
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    rebook(temp).then(response =>{
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                })
                    })
                    
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
            //2.不需补钱
            else if(this.orignPrice==this.realCost){
                this.$confirm("不需要补差价，选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                //进入直接创建新的订单，并自动支付
                rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                if(response.code===200){
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    //直接将旧订单修改为已改签
                    rebook(temp).then(response =>{
                        loading.close()
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                    })
                    })
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
            else{
                console.log('退还'+(this.orignPrice-this.realCost)+"元")
                this.$confirm("退还"+(this.orignPrice-this.realCost)+"元"+"，选购此座位？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                lock: true,
                text: '正拼命加载中......',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
                });
                //进入直接创建新的订单，并自动支付
                rebook1({username:this.name,passenger_card:this.oldOrder.passenger_card,train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,start_station_name:this.nowTrain.start_station,end_station_no:this.nowTrain.end_station_no,end_station_name:this.nowTrain.end_station,carriage_no:row.carriage_no,seat_no:this.seat_no,price:'￥'+this.realCost,create_time:this.create_time})
                .then(response =>{
                if(response.code===200){
                    //更新数据
                    querySeat({train_no:this.nowTrain.train_no,arrive_day:this.nowTrain.arrive_day,start_station_no:this.nowTrain.start_station_no,end_station_no:this.nowTrain.end_station_no})
                    .then(response =>{
                    this.occupation=response.data.cook
                    this.seat_info.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
                    this.occupation.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
                })
                    })
                    var temp =this.oldOrder
                    temp['order_id']=this.oldOrder.id
                    //直接将旧订单修改为已改签
                    rebook(temp).then(response =>{
                        loading.close()
                        this.active=3
                        this.$message({
                        message:response.data.message,
                        type:'success'
                    })
                    })
                }
                }).catch((response) => {
                        loading.close()}
                    )
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消选座'
            });          
            });
            }
        },
        handlePay(o){
        o['order_id']=o.id
        payTicket(o).then(response =>{
        console.log(response)
        var url =response.data.url
        window.open(url, "_blank")
        }).catch(error =>{
        console.log(error)
        })
        },
        },
    }

</script>

<style>
.box-card {
    width: 880px;
    margin-left: auto;
    margin-right: auto;
  }
</style>